#include "mainscene.h"
#include "ui_mainscene.h"
#include"config.h"
#include"map.h"
#include<QPainter>


MainScene::MainScene(QWidget *parent)
    : QWidget(parent)

{

    //调用初始化场景
    initScene();
    //启动游戏
    playGame();
}

MainScene::~MainScene()
{


}


void MainScene :: initScene() {
    //设置尺寸
    setFixedSize(GAME_WIDTH, GAME_HEIGHT);
    //设置标题
    setWindowTitle(GAME_TITLE);
    //设置定时器
    m_Timer.setInterval(GAME_RATE);

}

void MainScene::playGame(){
    //启动定时器
    m_Timer.start();
    //监听定时器信号
    connect(&m_Timer, &QTimer::timeout,[=](){
        //刷新游戏
        updatePoisition();
        update();
    });
}

void MainScene::paintEvent(QPaintEvent *){
    QPainter paint(this);
    paint.drawPixmap(0,0,m_map.m_map);

}

void MainScene::updatePoisition(){

}


void MainScene::loadTowerPositions()
{
    QPoint pos[] =
    {
        QPoint(65, 220),
        QPoint(155, 220),
        QPoint(245, 220),
        QPoint(335, 220),

        QPoint(100, 125),
        QPoint(195, 125),
        QPoint(280, 125),
        QPoint(370, 125),

        QPoint(80, 35),
        QPoint(170, 35),
        QPoint(260, 35),
        QPoint(350, 35)
    };
    int len	= sizeof(pos) / sizeof(pos[0]);

    for (int i = 0; i < len; ++i)
        m_towerPositionsList.push_back(pos[i]);
}
